Ext.namespace("Ext.viz.DomQuery");
Ext.viz.XmlReader = function() {
         Ext.viz.XmlReader.superclass.constructor.apply(this , arguments);
    };
       
       
    Ext.extend(Ext.viz.XmlReader  , Ext.data.XmlReader , {
 
        readRecords : function(doc) {
            this.xmlData = doc;
            var root = doc.documentElement || doc;
            var q = Ext.viz.DomQuery; // INSTEAD OF DomQuery
            var recordType = this.recordType, fields = recordType.prototype.fields;
            var sid = this.meta.id;
            var sidlocation = this.meta.idlocation;
            var totalRecords = 0, success = true;
            if(this.meta.totalRecords){
                totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
            }
            if(this.meta.success){
                var sv = q.selectValue(this.meta.success, root, true);
                success = sv !== false && sv !== 'false';
            }
            var records = [];
            var ns = q.select("//" + this.meta.record, root , this.meta.namespaceResolver);
            for(var i = 0, len = ns.length; i < len; i++) {
                var n = ns[i];
                var values = {};
                if(sidlocation == "attribute")
                    var id = sid ? q.selectValue(sid, n , this.meta.namespaceResolver) : undefined;
                else if (sidlocation == "content")
                        var id = sid ? q.selectNodeText(sid, n , this.meta.namespaceResolver) : undefined;
                for(var j = 0, jlen = fields.length; j < jlen; j++){
                    var f = fields.items[j];
                    if(f.location == "attribute")
                        var v = q.selectValue( (f.mapping || f.name), n, this.meta.namespaceResolver);
                    else if(f.location == "content")
                        var v =  q.selectNodeText( (f.mapping || f.name), n, this.meta.namespaceResolver);
                    v = f.convert(v, n);
                    values[f.name] = v;
                }
                var record = new recordType(values, id);
                record.node = n;
                records[records.length] = record;
            }
    
            return {
                success : success,
                records : records,
                totalRecords : totalRecords || records.length
            };
            
            
        }
    });
